package com.kingstar.flink.core.sql;


import com.kingstar.flink.core.api.TableInfo;
import com.kingstar.flink.core.utils.Constant;
import com.kingstar.flink.core.utils.GetTablesUtil;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.sql.*;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.calcite.shaded.com.google.common.collect.ImmutableList;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.calcite.FlinkPlannerImpl;
import org.apache.flink.table.calcite.FlinkTypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sound.midi.SysexMessage;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * SQL执行路径
 *
 * @author cailiming
 */
public class SqlTree {
    private static Logger logger = LoggerFactory.getLogger(SqlTree.class);
    public List<SqlLayer> sqlLayerList = new ArrayList<>();
    //存放join生成的临时流表名称
    private String tempStreamTableName = "";
    //存放临时流表别名
    private String StreamTableAliasName = "";
    //存放临时数据输出字段
    private List<SqlField> sqlFields = new ArrayList<>();
    //临时流表唯一索引标识
    private int tempStreamTableIndex = 1;

    /**
     * 解释并转化用户SQL为执行路径
     *
     * @param sqls 用户SQL
     */
    public void parse(String[] sqls, TableInfo[] tableInfos) {
        logger.debug("Explain User SQL\n" + StringUtils.join(sqls, "\n"));
        sqlLayerList = new ArrayList<SqlLayer>();

        Pattern InsertPattern = Pattern.compile("^insert\\s+(\\w+([-+.]\\w+)*)\\((.+)\\)");
        Pattern CreatePattern = Pattern.compile("^create\\s+temp\\s+table\\s+(\\w+([-+.]\\w+)*)\\s+as");

        //使用Flink调用calcite框架解析sql
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        TableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
        FrameworkConfig frameworkConfig = tableEnv.getFrameworkConfig();
        RelOptPlanner planner = tableEnv.getPlanner();
        FlinkTypeFactory typeFactory = tableEnv.getTypeFactory();
        FlinkPlannerImpl flinkPlanner = new FlinkPlannerImpl(frameworkConfig, planner, typeFactory);

        for (int i = 0; i < sqls.length; i++) {
            // 使用 SELECT 关键字拆分SQL
            int index = sqls[i].toLowerCase().indexOf("select");
            String targetSql = sqls[i].substring(0, index).trim();
            String calcSql = sqls[i].substring(index).trim();
            /**
             * insert into...select...
             * */
            if (targetSql.toLowerCase().startsWith("insert")) {
                String targetName = "";
                String[] columns = null;
                int index1 = targetSql.toLowerCase().indexOf("(");

                if (targetSql.substring(0, index1).trim().contains("INSERT INTO")) {
                    targetName = targetSql.substring(0, index1).trim().replace("INSERT INTO ", "").replaceAll("\\s*", "");
                } else {
                    targetName = targetSql.substring(0, index1).trim().replace("insert into ", "").replaceAll("\\s*", "");
                }
                columns = targetSql.substring(index1).replace("(", "").replace(")", "").replaceAll("\\s*", "").split(",");

                // 使用 FROM 关键字拆分calcSql
                int index2 = calcSql.toLowerCase().indexOf("from");
                String SELECTSQL = calcSql.substring(0, index2).trim();
                String FROMSQL = calcSql.substring(index2).trim();

                //insert into...select... => 流表join维表
                if (calcSql.toLowerCase().contains("join")) {
                    //使用Flink调用calcite框架解析sql
                    org.apache.calcite.sql.SqlNode sqlParse = flinkPlanner.parse(calcSql);
                    //System.out.println(sqlParse);
                    SqlSelect sqlSelect = (SqlSelect) sqlParse;

                    if ("JOIN".equals(sqlSelect.getFrom().getKind().toString())) {
                        SqlJoin sqlJoin = (SqlJoin) sqlSelect.getFrom();

                        //调用getSqlJoin()方法，递归遍历出所有SqlJoin对象，存入SqlJoin[]数组,返回SqlJoin[]
                        getSqlJoin(sqlJoin);
                        //反转sqlJoinsList
                        Collections.reverse(sqlJoinsList);

                        /**
                         *遍历sqlJoin,封装流维关联查询
                         *
                         */
                        for (SqlJoin sj : sqlJoinsList) {
                            SqlBasicCall sqlBasicCallRight = (SqlBasicCall) sj.getRight();

                            if ("org.apache.calcite.sql.SqlBasicCall".equals(sj.getLeft().getClass().getName().toString())) {
                                SqlBasicCall sqlBasicCallLeft = (SqlBasicCall) sj.getLeft();

                                if ("org.apache.calcite.sql.SqlIdentifier".equals(sqlBasicCallLeft.getOperands()[0].getClass().getName().toString())) {

                                    if ("org.apache.calcite.sql.SqlSelect".equals(sqlBasicCallRight.getOperands()[0].getClass().getName().toString())) {
                                        SqlSelect operand = (SqlSelect) sqlBasicCallRight.getOperands()[0];

                                        SqlStep sqlStep = new SqlStep();

                                        /**
                                         * 目标字段的详细信息
                                         * select a1.c1, a2.c2 from tab1 as a1 join tab2 as a2 on ... ==> [tab1.c1, tab2.c2]
                                         */
                                        for (TableInfo tableInfo : tableInfos) {

                                            if (tableInfo.getRegisterName().equalsIgnoreCase(sqlBasicCallLeft.getOperands()[0].toString().replace(".", "_"))) {
                                                sqlFields = GetSqlFields(tableInfo, sqlBasicCallLeft.getOperands()[0].toString(), sqlBasicCallLeft.getOperands()[1].toString());

                                            } else if (tableInfo.getRegisterName().equalsIgnoreCase(operand.getFrom().toString().replace(".", "_"))) {
                                                sqlFields = GetSqlFields(tableInfo, operand.getFrom().toString(), sqlBasicCallRight.getOperands()[1].toString());
                                            }
                                        }
                                        sqlStep.setTargetItems(sqlFields.toArray(new SqlField[sqlFields.size()]));

                                        StreamJoinDimSelect(sj, sqlStep, sqlBasicCallRight, sqlBasicCallLeft.getOperands()[0].toString());

                                    } else if ("org.apache.calcite.sql.SqlIdentifier".equals(sqlBasicCallRight.getOperands()[0].getClass().getName().toString())) {

                                        String righttableName = sqlBasicCallRight.getOperands()[0].toString();
                                        String rightTableAliasName = sqlBasicCallRight.getOperands()[1].toString();

                                        SqlLayer sqlLayer = new SqlLayer();
                                        SqlNode sqlNode = new SqlNode();
                                        SqlStep sqlStep = new SqlStep();

                                        /**
                                         * 执行的SQL类型
                                         */
                                        sqlStep.setSqlType(Constant.SQL_STREAM_JOIN_DIM);

                                        /**
                                         * SQL中查询的表
                                         */
                                        sqlStep.setTableNames(sqlBasicCallLeft.getOperands()[0].toString() + "," + righttableName);

                                        /**
                                         * 数据输出表名称
                                         * 规则：
                                         *     表名 = UUID.randomUUID()后拼接流表索引tempStreamTableIndex
                                         */
                                        sqlStep.setTargetName(UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex);
                                        //新增临时流表名
                                        tempStreamTableName = UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex;
                                        //临时流表索引自增
                                        tempStreamTableIndex++;

                                        /**
                                         * 查询条件
                                         * 使用场景：维表Join
                                         */
                                        sqlStep.setSqlCondition(sj.getCondition().toString());

                                        /**
                                         * 目标字段的详细信息
                                         * select a1.c1, a2.c2 from tab1 as a1 join tab2 as a2 on ... ==> [tab1.c1, tab2.c2]
                                         */
                                        String name = sqlBasicCallLeft.getOperands()[0].toString().replace(".", "_");
                                        for (TableInfo tableInfo : tableInfos) {
                                            String type = tableInfo.getType();
                                            if (tableInfo.getRegisterName().equalsIgnoreCase(name)) {
                                                sqlFields = GetSqlFields(tableInfo, sqlBasicCallLeft.getOperands()[0].toString(), sqlBasicCallLeft.getOperands()[1].toString());
                                            } else if (tableInfo.getRegisterName().equalsIgnoreCase(righttableName.replace(".", "_"))) {
                                                sqlFields = GetSqlFields(tableInfo, righttableName, rightTableAliasName);
                                            }
                                        }
                                        sqlStep.setTargetItems(sqlFields.toArray(new SqlField[sqlFields.size()]));

                                        /**
                                         * Join条件
                                         */
                                        List<SqlJoinCondition> sqlJoinConditions = GetCondition(sj);
                                        sqlStep.setJoinConditions(this.sqlJoinConditions.toArray(new SqlJoinCondition[this.sqlJoinConditions.size()]));

                                        /**
                                         * 封装SqlTree
                                         */
                                        sqlNode.addStep(sqlStep);
                                        sqlLayer.addNode(sqlNode);
                                        sqlLayerList.add(sqlLayer);
                                    }

                                } else if ("org.apache.calcite.sql.SqlSelect".equals(sqlBasicCallLeft.getOperands()[0].getClass().getName().toString())) {
                                    SqlLayer sqlLayer = new SqlLayer();
                                    SqlNode sqlNode = new SqlNode();
                                    SqlStep sqlStep = new SqlStep();

                                    sqlStep.setSqlType(Constant.SQL_CREATE_TABLE);
                                    String fromSql = sqlBasicCallLeft.getOperands()[0].toString();
                                    sqlStep.setSql(fromSql);

                                    sqlStep.setTableNames(GetTablesUtil.getTables(fromSql));

                                    /**
                                     * 数据输出表名称
                                     * 规则：
                                     *     表名 = UUID.randomUUID()后拼接流表索引tempStreamTableIndex
                                     */
                                    sqlStep.setTargetName(UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex);
                                    //新增临时流表名
                                    tempStreamTableName = UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex;
                                    //临时流表索引自增
                                    tempStreamTableIndex++;

                                    //存放全局流表别名
                                    StreamTableAliasName = sqlBasicCallLeft.getOperands()[1].toString();

                                    /**
                                     * 目标字段的详细信息
                                     * select a1.c1, a2.c2 from tab1 as a1 join tab2 as a2 on ... ==> [tab1.c1, tab2.c2]
                                     */
/*                                    SqlSelect operand = (SqlSelect) sqlBasicCallLeft.getOperands()[0];
                                    String name = ((SqlBasicCall) operand.getFrom()).getOperands()[0].toString().replace(".","_");
                                    for (TableInfo tableInfo : tableInfos) {
                                        if (tableInfo.getRegisterName().equalsIgnoreCase(name) &&  tableInfo.getType().equalsIgnoreCase(Constant.DATA_TYPE_KAFKA11)) {
                                            sqlFields = GetSqlFields(tableInfo, tempStreamTableName, StreamTableAliasName);
                                        }
                                    }*/

                                    sqlNode.addStep(sqlStep);
                                    sqlLayer.addNode(sqlNode);
                                    sqlLayerList.add(sqlLayer);

                                }
                            } else if ("org.apache.calcite.sql.SqlJoin".equals(sj.getLeft().getClass().getName().toString())) {
                                if ("org.apache.calcite.sql.SqlSelect".equals(sqlBasicCallRight.getOperands()[0].getClass().getName().toString())) {

                                    SqlSelect operand = (SqlSelect) sqlBasicCallRight.getOperands()[0];

                                    SqlStep sqlStep = new SqlStep();

                                    /**
                                     * 目标字段的详细信息
                                     * select a1.c1, a2.c2 from tab1 as a1 join tab2 as a2 on ... ==> [tab1.c1, tab2.c2]
                                     */

                                    sqlStep.setTargetItems(sqlFields.toArray(new SqlField[sqlFields.size()]));

                                    StreamJoinDimSelect(sj, sqlStep, sqlBasicCallRight, tempStreamTableName);

                                } else if ("org.apache.calcite.sql.SqlIdentifier".equals(sqlBasicCallRight.getOperands()[0].getClass().getName().toString())) {
                                    SqlLayer sqlLayer = new SqlLayer();
                                    SqlNode sqlNode = new SqlNode();
                                    SqlStep sqlStep = new SqlStep();

                                    /**
                                     * 执行的SQL类型
                                     */
                                    sqlStep.setSqlType(Constant.SQL_STREAM_JOIN_DIM);

                                    /**
                                     * SQL中查询的表
                                     */
                                    sqlStep.setTableNames(tempStreamTableName + "," + sqlBasicCallRight.getOperands()[0].toString());

                                    /**
                                     * 数据输出表名称
                                     * 规则：
                                     *     表名 = UUID.randomUUID()后拼接流表索引tempStreamTableIndex
                                     */
                                    sqlStep.setTargetName(UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex);
                                    //新增临时流表名
                                    tempStreamTableName = UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex;
                                    //临时流表索引自增
                                    tempStreamTableIndex++;

                                    /**
                                     * 查询条件
                                     * 使用场景：维表Join
                                     */
                                    sqlStep.setSqlCondition(sj.getCondition().toString());

                                    /**
                                     * Join条件
                                     */
                                    List<SqlJoinCondition> sqlJoinConditions = GetCondition(sj);
                                    sqlStep.setJoinConditions(this.sqlJoinConditions.toArray(new SqlJoinCondition[this.sqlJoinConditions.size()]));

                                    /**
                                     * 目标字段的详细信息
                                     * select a1.c1, a2.c2 from tab1 as a1 join tab2 as a2 on ... ==> [tab1.c1, tab2.c2]
                                     */
                                    sqlStep.setTargetItems(sqlFields.toArray(new SqlField[sqlFields.size()]));

                                    /**
                                     * 封装SqlTree
                                     */
                                    sqlNode.addStep(sqlStep);
                                    sqlLayer.addNode(sqlNode);
                                    sqlLayerList.add(sqlLayer);

                                }
                            }
                        }

                        /**
                         * insert into ...
                         *  select ...
                         *  from [最终的临时流表]
                         *  where ...
                         *  group by ...
                         *
                         **/
                        SqlLayer sqlLayer = new SqlLayer();
                        SqlNode sqlNode = new SqlNode();
                        SqlStep sqlStep = new SqlStep();
                        sqlStep.setSqlType(Constant.SQL_INSERT);


                        String sqlText = targetSql + "\n" + SELECTSQL + "\n" + "FROM\n" + tempStreamTableName + "\n";
                        if (sqlSelect.getWhere() != null) {
                            sqlText += "WHERE\n" + sqlSelect.getWhere().toString();
                        }

                        if (sqlSelect.getGroup() != null) {
                            sqlText += "GROUP BY\n" + sqlSelect.getGroup().toString();
                        }
                        System.out.println("-------------------------------------------------------------------------------");
                        System.out.println(sqlText);
                        sqlStep.setSql(sqlText);

                        sqlStep.setTableNames(tempStreamTableName);
                        sqlStep.setTargetName(targetName);

                        /**
                         * 目标表字段
                         * insert into table => null
                         * insert into table(c1,c2) ==> [c1,c2]
                         *
                         */
                        sqlStep.setTargetFields(columns);

                        sqlNode.addStep(sqlStep);
                        sqlLayer.addNode(sqlNode);
                        sqlLayerList.add(sqlLayer);

                        System.out.println("流维join封装完毕");

                    }
                }
                //insert into...select... => 常规flinkSql
                else {

                }
            }
            /**
             * create...select...
             * */
            else if (targetSql.toLowerCase().startsWith("create")) {

                String targetName = "";
                Matcher matcher = CreatePattern.matcher(targetSql.toLowerCase());
                if (matcher.find()) {
                    targetName = matcher.group(1);
                }
                //create...select... => 流表join维表
                if (calcSql.toLowerCase().contains("join")) {
                    //使用Flink调用calcite框架解析sql
                    org.apache.calcite.sql.SqlNode sqlParse = flinkPlanner.parse(calcSql);
                    //System.out.println(sqlParse);
                }
                //create...select... => 常规flinkSql
                else {
                    SqlLayer sqlLayer = new SqlLayer();
                    SqlNode sqlNode = new SqlNode();
                    SqlStep sqlStep1 = new SqlStep();

                    sqlStep1.setSqlType(Constant.SQL_CREATE_TABLE);
                    sqlStep1.setSql(calcSql);

                    sqlStep1.setTableNames(GetTablesUtil.getTables(calcSql));

                    sqlStep1.setTargetName(targetName + "TempTable");

                    sqlNode.addStep(sqlStep1);
                    sqlLayer.addNode(sqlNode);
                    sqlLayerList.add(sqlLayer);
                }
            }

            /**
             * update...select...
             * */
            else if (targetSql.toLowerCase().startsWith("update")) {
                //update...select... => 流表join维表
                if (calcSql.toLowerCase().contains("join")) {
                }
                //update...select... => 常规flinkSql
                else {
                }
            }
        }

        System.out.println("Sql解析封装完毕！");
    }

    /**
     * get layer list
     *
     * @return
     */
    public List<SqlLayer> getSqlLayerList() {
        return sqlLayerList;
    }

    /**
     * 递归遍历出所有SqlJoin对象，存入sqlJoinsList集合
     */
    List<SqlJoin> sqlJoinsList = new ArrayList<>();

    public void getSqlJoin(org.apache.calcite.sql.SqlJoin sqlJoin) {
        if ("org.apache.calcite.sql.SqlJoin".equals(sqlJoin.getLeft().getClass().getName().toString())) {
            sqlJoinsList.add(sqlJoin);
            getSqlJoin((SqlJoin) sqlJoin.getLeft());
        } else if ("org.apache.calcite.sql.SqlBasicCall".equals(sqlJoin.getLeft().getClass().getName().toString())) {
            sqlJoinsList.add(sqlJoin);
        }
    }

    /**
     * 解析Join的 sqlField 输出字段
     *
     * @return List<SqlField>
     */
    public List<SqlField> GetSqlFields(TableInfo tableInfo, String tableName, String aliasName) {

        String[] fields = tableInfo.getFields();

        for (int j = 0; j < fields.length; j++) {
            int coltype = 0;
            if ("datatime".equals(fields[j])) {
                coltype = SqlField.TYPE_ROWTIME;
            } else {
                coltype = SqlField.TYPE_SOURCE;
            }
            SqlField sqlField = new SqlField(tableName, fields[j], aliasName, coltype);
            sqlFields.add(sqlField);

            SqlField sqlField1 = sqlFields.get(j);
        }

        return sqlFields;
    }

    /**
     * 解析Join的condition条件
     * <p>
     * return List<SqlJoinCondition>
     */
    List<SqlJoinCondition> sqlJoinConditions = new ArrayList<>();

    public List<SqlJoinCondition> GetCondition(SqlJoin sqlJoin) {
        SqlBasicCall condition = (SqlBasicCall) sqlJoin.getCondition();
        org.apache.calcite.sql.SqlNode[] sqlNodes = condition.getOperands();


        if ("org.apache.calcite.sql.SqlBasicCall".equals(condition.getOperands()[0].getClass().getName().toString())) {
            GetOnConditions(sqlNodes);
        } else if ("org.apache.calcite.sql.SqlIdentifier".equals(condition.getOperands()[0].getClass().getName().toString())) {
            SqlIdentifier leftIdentifier = (SqlIdentifier) condition.getOperands()[0];
            SqlIdentifier rightIdentifier = (SqlIdentifier) condition.getOperands()[1];
            SqlJoinCondition sqlJoinCondition = new SqlJoinCondition(leftIdentifier.names.get(0).toString(),
                    leftIdentifier.names.get(1).toString(),
                    rightIdentifier.names.get(0).toString(),
                    rightIdentifier.names.get(1).toString(), Constant.JOIN_EQUAL);
            sqlJoinConditions.add(sqlJoinCondition);
        }

        return sqlJoinConditions;
    }

    /**
     * 流表join维表子查询，解析成先关联再过滤
     */
    public void StreamJoinDimSelect(SqlJoin sj, SqlStep sqlStep, SqlBasicCall sqlBasicCallRight, String StreamTable) {
        SqlSelect operand = (SqlSelect) sqlBasicCallRight.getOperands()[0];

        String whereText = "";
        SqlBasicCall where = (SqlBasicCall) operand.getWhere();
        if ("org.apache.calcite.sql.SqlBasicCall".equals(where.getOperands()[0].getClass().getName().toString())) {
            for (org.apache.calcite.sql.SqlNode sqlNode : where.getOperands()) {
                if (whereText != "") {
                    whereText += "AND";
                }
                whereText += sqlNode.toString();
            }
        } else {
            whereText = operand.getWhere().toString();
        }

        //第一步:先流表关联维表
        /**
         * 执行的SQL类型
         */
        SqlLayer sqlLayer = new SqlLayer();
        SqlNode sqlNode = new SqlNode();
        sqlStep.setSqlType(Constant.SQL_STREAM_JOIN_DIM);

        /**
         * SQL中查询的表
         */
        sqlStep.setTableNames(StreamTable + "," + operand.getFrom().toString());

        /**
         * 数据输出表名称
         * 规则：
         *     表名 = UUID.randomUUID()后拼接流表索引tempStreamTableIndex
         */
        sqlStep.setTargetName(UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex);
        //存储临时流表名
        tempStreamTableName = UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex;
        //临时流表索引自增
        tempStreamTableIndex++;

        /**
         * 查询条件
         * 使用场景：维表Join
         */
        sqlStep.setSqlCondition(sj.getCondition().toString());

        /**
         * Join条件
         */
        List<SqlJoinCondition> sqlJoinConditions = GetCondition(sj);
        sqlStep.setJoinConditions(this.sqlJoinConditions.toArray(new SqlJoinCondition[this.sqlJoinConditions.size()]));


        /**
         * 封装SqlTree
         */
        sqlNode.addStep(sqlStep);
        sqlLayer.addNode(sqlNode);
        sqlLayerList.add(sqlLayer);

        //第二步:后过滤流表
        SqlLayer sqlLayer2 = new SqlLayer();
        SqlNode sqlNode2 = new SqlNode();
        SqlStep sqlStep2 = new SqlStep();

        String sql = "select *\n" + "from\n" + tempStreamTableName + "\n" + "where\n" + whereText;

        sqlStep2.setSqlType(Constant.SQL_CREATE_TABLE);
        sqlStep2.setSql(sql);

        sqlStep2.setTableNames(tempStreamTableName);

        /**
         * 数据输出表名称
         * 规则：
         *     表名 = UUID.randomUUID()后拼接流表索引tempStreamTableIndex
         */
        sqlStep2.setTargetName(UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex);
        //新增临时流表名
        tempStreamTableName = UUID.randomUUID().toString().substring(0, 8) + tempStreamTableIndex;
        //临时流表索引自增
        tempStreamTableIndex++;

        sqlNode2.addStep(sqlStep2);
        sqlLayer2.addNode(sqlNode2);
        sqlLayerList.add(sqlLayer2);
    }


    /**
     * 递归遍历left join ON [多条件]
     * return List<SqlJoinCondition>
     */
    public void GetOnConditions(org.apache.calcite.sql.SqlNode[] sqlNodes) {
        for (org.apache.calcite.sql.SqlNode sqlNode : sqlNodes) {
            SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;

            if ("AND".equals(sqlBasicCall.getOperator().toString())) {
                GetOnConditions(sqlBasicCall.getOperands());
            } else if ("=".equals(sqlBasicCall.getOperator().toString())) {
                SqlIdentifier leftIdentifier = (SqlIdentifier) sqlBasicCall.getOperands()[0];
                SqlIdentifier rightIdentifier = (SqlIdentifier) sqlBasicCall.getOperands()[1];

                SqlJoinCondition sqlJoinCondition = new SqlJoinCondition(leftIdentifier.names.get(0).toString(),
                        leftIdentifier.names.get(1).toString(),
                        rightIdentifier.names.get(0).toString(),
                        rightIdentifier.names.get(1).toString(), Constant.JOIN_EQUAL);
                sqlJoinConditions.add(sqlJoinCondition);
            }
        }
    }
}
